package com.school.service;

import com.school.dao.studentMapper;
import com.school.pojo.Page;
import com.school.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class studentServiceImpl implements studentService {
    @Autowired
    private studentMapper studentMapper;
    public int insertStudent(Student student) {
        Student student1 = student;
        long date = student1.getCreate_time().getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        Map<String,Object> map=new HashMap<>();
        map.put("user_id",student1.getUser_id());
        map.put("user_name",student1.getUser_name());
        map.put("user_password",student1.getUser_password());
        map.put("create_time",dateString);
        int i =studentMapper.insertStudent(map);
        System.out.println(map);
        return i;
    }

    public int delStudent(int id) {
        return studentMapper.delStudent(id);
    }

    public int updateStudent(Student student) {
        Student student1 = student;
        long date = student1.getCreate_time().getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(date);
        Map<String,Object> map=new HashMap<>();
        map.put("user_id",student1.getUser_id());
        map.put("user_name",student1.getUser_name());
        map.put("user_password",student1.getUser_password());
        map.put("create_time",dateString);
        int i =studentMapper.updateStudent(map);
        return i;
    }

    public List<Student> queryStudent(Map map) {
        return studentMapper.queryStudent(map);
    }

    public List<Student> queryAll() {
        return studentMapper.queryAll();
    }

    public int queryNumber() {
        return studentMapper.queryNumber();
    }

    public List<Student> queryStuByPage(Page page) {
        int page1=page.getCurrentPage();
        int num=page.getPageSize();
        page.setCurrentPage((page1-1)*num);
        return studentMapper.queryStuByPage(page);
    }

    @Override
    public int queryStuByPageNum(Map  page) {
        return studentMapper.queryStuByPageNum(page);
    }
}
